package com.example.administrator.x3picturetransliteration.Home.Activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.x3picturetransliteration.Base.BaseActivity;
import com.example.administrator.x3picturetransliteration.Base.BasePresenter;
import com.example.administrator.x3picturetransliteration.Home.Presenter.Activity.CommonProblemDetailsPresenter;
import com.example.administrator.x3picturetransliteration.R;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 常见问题详情
 * Created by Administrator on 2019/8/26.
 */

public class CommonProblemDetailsActivity extends BaseActivity{

    public static void startCommonProblemDetailsActivity(Context context,String id){

        Intent intent = new Intent(context,CommonProblemDetailsActivity.class);
        intent.putExtra("id",id);
        context.startActivity(intent);

    }

    @BindView(R.id.TitleText)TextView TitleText;
    @BindView(R.id.LButton)ImageView LButton;

    @BindView(R.id.WenTiText)TextView WenTiText;
    @BindView(R.id.webView)WebView webView;

    private CommonProblemDetailsPresenter mCommonProblemDetailsPresenter;

    @Override
    public int intiLayout() {
        return R.layout.home_activity_common_problem_details;

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TitleText.setText("常见问题");
        LButton.setImageResource(R.mipmap.home_backw);

        mCommonProblemDetailsPresenter = new CommonProblemDetailsPresenter(this,mCompositeSubscriptions);

        mCommonProblemDetailsPresenter.get(getIntent().getStringExtra("id"), new BasePresenter.Callback() {
            @Override
            public void getData(Object data) {

                Map<String,String> map = (Map<String, String>)data;

                WenTiText.setText(map.get("title")!=null?map.get("title"):"");

                webView.loadDataWithBaseURL(null, "<head><style>img{max-width:100% !important;}</style></head>" + map.get("content")!=null?map.get("content"):"" , "text/html", "UTF-8", null);
            }
        });
    }

    @OnClick(R.id.left_button)
    public void left_buttonClick(){

        finish();
    }
}
